/**
 * 医疗空间数字孪生 - 设计系统类型定义
 * 为设计系统提供TypeScript类型支持
 */

// 颜色主题类型
export type ColorScale = {
  50: string;
  100: string;
  200: string;
  300: string;
  400: string;
  500: string;
  600: string;
  700: string;
  800: string;
  900: string;
};

export type SemanticColors = {
  success: string;
  warning: string;
  error: string;
  info: string;
};

export type VisualizationColors = {
  heatmapLow: string;
  heatmapMedium: string;
  heatmapHigh: string;
  trajectoryNormal: string;
  trajectoryEmergency: string;
  bottleneck: string;
  optimizedPath: string;
};

export type ThreeDColors = {
  wall: string;
  floor: string;
  door: string;
  window: string;
  asset: string;
};

export type DesignTokens = {
  colors: {
    primary: ColorScale;
    secondary: ColorScale;
    gray: ColorScale;
    semantic: SemanticColors;
    visualization: VisualizationColors;
    threeD: ThreeDColors;
    background: string;
    surface: string;
    surfaceElevated: string;
    textPrimary: string;
    textSecondary: string;
    textDisabled: string;
    textOnPrimary: string;
    textOnSecondary: string;
  };
  spacing: {
    1: string;
    2: string;
    3: string;
    4: string;
    5: string;
    6: string;
    7: string;
    8: string;
  };
  radius: {
    small: string;
    medium: string;
    large: string;
    full: string;
  };
  shadows: {
    1: string;
    2: string;
    3: string;
  };
  borders: {
    light: string;
    medium: string;
    heavy: string;
  };
  breakpoints: {
    xs: string;
    sm: string;
    md: string;
    lg: string;
    xl: string;
  };
};

// 组件变体类型
export type ButtonVariant = 'primary' | 'secondary' | 'outline' | 'ghost';
export type ButtonSize = 'small' | 'medium' | 'large';

export type CardVariant = 'default' | 'elevated' | 'compact';

export type AlertVariant = 'critical' | 'warning' | 'info' | 'success';

export type StatusType = 'online' | 'offline' | 'warning';

export type TrajectoryType = 'normal' | 'emergency' | 'bottleneck' | 'optimized';

// 组件props类型
export interface ButtonProps {
  variant?: ButtonVariant;
  size?: ButtonSize;
  disabled?: boolean;
  loading?: boolean;
  children: React.ReactNode;
  onClick?: () => void;
  className?: string;
}

export interface CardProps {
  variant?: CardVariant;
  title?: string;
  subtitle?: string;
  children: React.ReactNode;
  className?: string;
}

export interface KPICardProps {
  label: string;
  value: string | number;
  change?: {
    value: number;
    type: 'positive' | 'negative' | 'neutral';
  };
  unit?: string;
  className?: string;
}

export interface AlertTagProps {
  variant: AlertVariant;
  children: React.ReactNode;
  icon?: React.ReactNode;
  className?: string;
}

export interface StatusIndicatorProps {
  status: StatusType;
  label: string;
  className?: string;
}

export interface TimelineProps {
  duration: number;
  currentTime: number;
  isPlaying: boolean;
  speed: number;
  onTimeChange: (time: number) => void;
  onPlayPause: () => void;
  onSpeedChange: (speed: number) => void;
  className?: string;
}

export interface HeatmapLegendProps {
  minValue: number;
  maxValue: number;
  unit?: string;
  className?: string;
}

export interface FloorSwitcherProps {
  floors: Array<{
    id: string;
    name: string;
    level: number;
  }>;
  activeFloor: string;
  onFloorChange: (floorId: string) => void;
  className?: string;
}

export interface ViewerControlProps {
  icon: React.ReactNode;
  active?: boolean;
  onClick: () => void;
  tooltip?: string;
  className?: string;
}

export interface PerformanceMetricProps {
  label: string;
  value: number;
  unit: string;
  trend?: number[];
  className?: string;
}

export interface CloudRenderStatusProps {
  status: 'loading' | 'connected' | 'error';
  message: string;
  className?: string;
}

// 实用工具类型
export type SpacingValue = keyof DesignTokens['spacing'];
export type ColorValue = string;
export type RadiusValue = keyof DesignTokens['radius'];
export type ShadowValue = keyof DesignTokens['shadows'];

// CSS-in-JS样式对象类型
export interface StyleObject {
  [property: string]: string | number | StyleObject;
}

// 主题配置类型
export interface ThemeConfig {
  mode: 'light' | 'dark' | 'auto';
  primaryColor?: string;
  secondaryColor?: string;
  customColors?: Record<string, string>;
}

// 响应式工具类型
export type Breakpoint = keyof DesignTokens['breakpoints'];

export interface ResponsiveValue<T> {
  xs?: T;
  sm?: T;
  md?: T;
  lg?: T;
  xl?: T;
}

// CSS变量名称类型（用于类型安全的CSS变量访问）
export type CSSVariable = 
  | `--primary-${keyof ColorScale}`
  | `--secondary-${keyof ColorScale}`
  | `--gray-${keyof ColorScale}`
  | '--success'
  | '--warning'
  | '--error'
  | '--info'
  | '--heatmap-low'
  | '--heatmap-medium'
  | '--heatmap-high'
  | '--trajectory-normal'
  | '--trajectory-emergency'
  | '--bottleneck'
  | '--optimized-path'
  | '--3d-wall'
  | '--3d-floor'
  | '--3d-door'
  | '--3d-window'
  | '--3d-asset'
  | '--background'
  | '--surface'
  | '--surface-elevated'
  | '--text-primary'
  | '--text-secondary'
  | '--text-disabled'
  | '--text-on-primary'
  | '--text-on-secondary'
  | `--space-${keyof DesignTokens['spacing']}`
  | `--radius-${keyof DesignTokens['radius']}`
  | `--shadow-${keyof DesignTokens['shadows']}`
  | '--border-light'
  | '--border-medium'
  | '--border-heavy'
  | `--breakpoint-${keyof DesignTokens['breakpoints']}`;

// 工具函数类型
export type GetCSSVariable = (variable: CSSVariable) => string;
export type SetCSSVariable = (variable: CSSVariable, value: string) => void;

// 动画配置类型
export interface AnimationConfig {
  duration: number;
  easing: string;
  delay?: number;
}

// 可访问性相关类型
export interface A11yProps {
  'aria-label'?: string;
  'aria-labelledby'?: string;
  'aria-describedby'?: string;
  'aria-expanded'?: boolean;
  'aria-hidden'?: boolean;
  role?: string;
  tabIndex?: number;
}

// 事件处理器类型
export type ClickHandler = (event: React.MouseEvent<HTMLElement>) => void;
export type ChangeHandler<T = string> = (value: T) => void;
export type KeyboardHandler = (event: React.KeyboardEvent<HTMLElement>) => void;

// 医疗特定数据类型
export interface HeatmapData {
  x: number;
  y: number;
  value: number;
  intensity?: number;
}

export interface TrajectoryPoint {
  x: number;
  y: number;
  timestamp: number;
  type: TrajectoryType;
  metadata?: Record<string, any>;
}

export interface FloorPlan {
  id: string;
  name: string;
  level: number;
  bounds: {
    width: number;
    height: number;
  };
  features: Array<{
    id: string;
    type: 'room' | 'corridor' | 'entrance' | 'exit' | 'equipment';
    geometry: any; // GeoJSON-like geometry
    properties: Record<string, any>;
  }>;
}

export interface KPIData {
  id: string;
  label: string;
  value: number;
  unit: string;
  change?: {
    value: number;
    timeframe: string;
  };
  target?: number;
  status: 'good' | 'warning' | 'critical';
}

// 组件状态类型
export interface LoadingState {
  isLoading: boolean;
  progress?: number;
  message?: string;
}

export interface ErrorState {
  hasError: boolean;
  message?: string;
  details?: any;
}

// 数据获取相关类型
export interface ApiResponse<T = any> {
  data: T;
  success: boolean;
  message?: string;
  errors?: string[];
}

export interface PaginatedResponse<T = any> extends ApiResponse<T[]> {
  pagination: {
    page: number;
    limit: number;
    total: number;
    totalPages: number;
  };
}

// 导出所有类型的联合类型，便于使用
export type DesignSystemTypes = {
  ButtonVariant: ButtonVariant;
  ButtonSize: ButtonSize;
  CardVariant: CardVariant;
  AlertVariant: AlertVariant;
  StatusType: StatusType;
  TrajectoryType: TrajectoryType;
  Breakpoint: Breakpoint;
  CSSVariable: CSSVariable;
  SpacingValue: SpacingValue;
  RadiusValue: RadiusValue;
  ShadowValue: ShadowValue;
}; 